<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

/**
 * Facilitate the collection of a NZ bank account number from the visitor
 * @author Anthony Gallon
 * @package Antz
 */


/**
 * Facilitate the collection of a NZ bank account number from the visitor
 * @author Anthony Gallon
 * @package Antz
 */

class JFX_Form_Components_BankNumber extends JFX_Form_Component
{
     /**
      * Set some initial values
      * @param string $name
      * @param string $label
      * @param array $value
      * @param string $id
      */
     public function __construct($name, $label, $value=array(), $id=''){
         if(count($value)==0){
             $value = array('bank'=>'', 'branch'=>'', 'account'=>'', 'suffix'=>'');
         };
         if($id=='') $id = 'bank'.rand();
         $this->id = $id;
         $this->val = $value['account'];
         $this->name = $name;
         $this->label = $label;
         $this->bank = new JFX_Form_Components_Input('text', $name.'Bank', '', $value['bank']);
         $this->bank->showLabel(false);
         $this->bank->setWrap(false);
         $this->bank->addClass('extraShort marginRightMin');
         $this->branch = new JFX_Form_Components_Input('text', $name.'Branch', '', $value['branch']);
         $this->branch->showLabel(false);
         $this->branch->setWrap(false);
         $this->branch->addClass('short marginRightMin');
         $this->account = new JFX_Form_Components_Input('text', $name.'Account', '', $value['account']);
         $this->account->showLabel(false);
         $this->account->setWrap(false);
         $this->account->addClass('med marginRightMin');
         $this->suffix = new JFX_Form_Components_Input('text', $name.'Suffix', '', $value['suffix']);
         $this->suffix->showLabel(false);
         $this->suffix->setWrap(false);
         $this->suffix->addClass('extraShort marginRightMin');
     }

     /**
      * Get the bank account number from the submitted data, formatted accordingly
      * @param string $name
      * @return string $number
      */
     public static function getNumberFromForm($name){
         $bank = trim(post($name.'Bank'));
         $branch = trim(post($name.'Branch'));
         $acct = trim(post($name.'Account'));
         $suff = trim(post($name.'Suffix'));
         return trim($bank.' '.$branch.' '.$acct.' '.$suff);
     }

     /**
      * Return the element as an HTML string
      * @global object $gCms
      * @return string $html
      */
     public function render(){
     	$CONFIG = JFX::registry('config');
     	 if($this->required) $this->aftertext = '<span class="required"><img src="'.$CONFIG->baseUrl.'/jfx/images/required.gif" alt="Required" /></span>'.$this->aftertext;
         $returnString = $this->bank->render().$this->branch->render().$this->account->render().$this->suffix->render();
         if($this->showLabel) $returnString = '<label for="'.$this->getId().'">'.$this->label.'</label>'.$returnString;
         if($this->wrap) $returnString = $this->wrap($returnString);
         return $returnString;
     }

}
